import * as grpc from '@grpc/grpc-js'
import { TestService } from './gen//test_grpc_pb'
import { TestRes } from './gen/test_pb'

const server = new grpc.Server()
server.addService(TestService, {
	sayTest(call: any, callback: Function) {
		call.on('data', (data: any) => {
			console.log('data', data)
			const res = new TestRes()
			res.setName('Test')
			call.write(res)
		})
	},
})

server.bindAsync('localhost:3333', grpc.ServerCredentials.createInsecure(), (err, port) => {
	if (err) {
		console.error('Failed to bind:', err)
		return
	}
	console.log('RPC服务启动')
})
